﻿using Digitalmes.Services.Communication;
using DotLiquid.Tags;
using System;

namespace Digitalmes.Services
{
    public class DriverService : BaseService, ITransient
    {
        
       
        public DriverService(IServiceProvider serviceProvider) : base(serviceProvider)
        {
        }


        public async Task<ServiceResponse> LoadDriver(DriverParameter para)
        {
            var response = new ServiceResponse();
            try
            {
                 switch (para.DriverType)
                 {
                    case Model.DriverTypeEnum.OpcUa:                     
                         var opc=GetService<OpcUaDriver>();
                         response = await opc.ConnectAsync(para);
                        break;  
                    default:
                        throw new Exception("系统不支持此驱动");              
                 }            
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                response.Exception = ex;
                Log.Error("加载驱动失败", ex);

            }
            return response;
        }

    }
}
